package gui;

import java.awt.Dimension;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.sql.ResultSet;

import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTable;

public class showregister extends JFrame {
    private JPanel jPanel1 = new JPanel();
    private JLabel jLabel1 = new JLabel();
    private JComboBox jComboBox1 = new JComboBox();
    private JButton jButton1 = new JButton();
    String sname;
    private JButton jButton2 = new JButton();
    private JButton jButton3 = new JButton();
    private JLabel jLabel2 = new JLabel();
    private JLabel jLabel3 = new JLabel();

    public showregister() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout( null );
        this.setSize(new Dimension(549, 389));
        jPanel1.setBounds(new Rectangle(0, 0, 550, 365));
        jPanel1.setLayout(null);
        jLabel1.setText("student name");
        jLabel1.setBounds(new Rectangle(25, 40, 90, 25));
        jComboBox1.setBounds(new Rectangle(130, 45, 200, 20));
        jComboBox1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jComboBox1_actionPerformed(e);
                }
            });
        jButton1.setText("show");
        jButton1.setBounds(new Rectangle(345, 45, 70, 20));
        jButton1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        jButton1_actionPerformed(e);
                    } catch (SQLException f) {
                    }
                }
            });
        jButton2.setText("show courses");
        jButton2.setBounds(new Rectangle(65, 100, 115, 20));
        jButton2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        jButton2_actionPerformed(e);
                    } catch (SQLException f) {
                    }
                }
            });
        jButton3.setText("back");
        jButton3.setBounds(new Rectangle(420, 330, 75, 21));
        jButton3.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jButton3_actionPerformed(e);
                }
            });
        jLabel2.setBounds(new Rectangle(40, 160, 175, 55));
        jLabel3.setBounds(new Rectangle(240, 165, 200, 160));
        jPanel1.add(jLabel3, null);
        jPanel1.add(jLabel2, null);
        jPanel1.add(jButton3, null);
        jPanel1.add(jButton2, null);
        jPanel1.add(jButton1, null);
        jPanel1.add(jComboBox1, null);
        jPanel1.add(jLabel1, null);
        this.getContentPane().add(jPanel1, null);
        this.setVisible(true);
    }

    private void jButton1_actionPerformed(ActionEvent e) throws SQLException {
        
        //----------------
        database t=new database();
        String select=" select * from students ";
        ResultSet rs=t.check(select);
        
        while(rs.next()){
                String studentname=rs.getString(2);
                jComboBox1.addItem(studentname);

            }
    }

    private void jComboBox1_actionPerformed(ActionEvent e) {
        sname=jComboBox1.getSelectedItem().toString();
    }

    private void jButton2_actionPerformed(ActionEvent e) throws SQLException {
       String select= "SELECT * FROM `re_course` WHERE  sname='"+sname+"' ";
       database t=new database();
       ResultSet r=t.check(select);
       int row=0;
       while(r.next()){
          
          
          jLabel2.setText(r.getString(1)); 
           jLabel3.setText(r.getString(2)); 
          // jTable1.setValueAt(r.getString(1), row, 0);
          // jTable1.setValueAt(r.getString(2), row, 1);
           row++;
       }
       
    }

    private void jButton3_actionPerformed(ActionEvent e) {
        //back
        real_project re=new real_project();
        this.setVisible(false);
    }
}
